import axios from '@/libs/api.request'
import config from '@/config'

export const getTeamSendTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SMSService.viewGroups',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editTeamSendRecord = async (playload) => {
  const data = {
    module: 'SMSService.addGroup',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const deleteTeamSendRecord = async (playload) => {
  const data = {
    module: 'SMSService.delGroup',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getGroupDetailTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SMSService.groupUsers',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const getSmsTemplateTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SMSService.viewTemps',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const editSmsTemplateRecord = async (playload) => {
  let module_name = 'SMSService.addTemp'
  if (playload.id && playload.id !== '') {
    module_name = 'SMSService.updateTemp'
  }
  const data = {
    module: module_name,
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const deleteSmsTemplateRecord = async (playload) => {
  const data = {
    module: 'SMSService.delTemp',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}

export const getSendDataTable = async (playload) => {
  const resp = await axios.request({
    url: config.apiUrl,
    params: {
      module: 'SMSService.viewTasks',
      ...playload
    },
    method: 'get'
  })
  return resp
}

export const sendSmsRecord = async (playload) => {
  const data = {
    module: 'SMSService.addTask',
    ...playload
  }
  const resp = await axios.request({
    url: config.postUrl,
    data,
    method: 'post'
  })
  return resp
}
